package day2.assignments;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BillPayment
 */
@WebServlet(name = "Billpayment", urlPatterns = { "/BillPayment" })
public class BillPayment extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private String customerCare;
	private ServletContext ctx;

	public void init(ServletConfig cfg) throws ServletException {
		super.init(cfg);
		this.ctx = getServletContext();
		customerCare = ctx.getInitParameter("CustomerCare");
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		try {
			response.setContentType("text/html");
			PrintWriter out = response.getWriter();
			out.write("Bill Amount = " + request.getParameter("amt"));
			out.write("<br/>Payment Mode = " + request.getParameter("mode"));
			out.write("<br/>Plans opted =");
			for (String i : request.getParameterValues("plan"))
				out.write(" " + i);
			out.write("<br/>Customer Care: " + customerCare);
			out.close();
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}
}
